﻿using System;
using System.Text;

namespace Mvc.XForms.Utilities {
	public static class StringExtensions {
		/// <summary>
		/// Inserts spaces before capitals in a string, eg "ThisIsAString" becomes "This Is A String"
		/// </summary>
		public static string CapitalizeSpace(this string text) {
			var sb = new StringBuilder();
			var lowered = text.ToLower();

			for (int i = 0; i < text.Length; i++) {
				var a = text.Substring(i, 1);
				var b = lowered.Substring(i, 1);
				if (a != b)
					sb.Append(" ");
				sb.Append(a);
			}

			return sb.ToString().Trim();
		}
	}
}